package com.harboursoftware.xstorage.unit.db.sql

import java.sql.Connection;
import java.sql.DriverManager 
import java.sql.SQLException;
import org.apache.commons.dbutils.DbUtils;
import com.harboursoftware.xstorage.db.sql.DatabaseProvider;
import com.harboursoftware.xstorage.XStorageException;

/**
 * DatabaseProvider的内存数据库实现，该类初始化时会启动内存数据库Derby。
 *
 * @deprecated
 * @author Simon Leung
 * @since 0.1
 */
class InMemoryDatabaseProvider implements DatabaseProvider {
    static jdbcUrl = 'jdbc:hsqldb:mem:testDB;shutdown=true'
    static jdbcUsername = 'sa'
    static jdbcPassword = ''
    
    static void startDatabase() {
        def driver = "org.hsqldb.jdbc.JDBCDriver"
        DbUtils.loadDriver(driver)
    }

    static void shutdownDatabase() {
        DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword)
    }
    
    @Override
    public Connection getConnection() throws SQLException {
        DriverManager.getConnection("jdbc:hsqldb:mem:testDB", "sa", "")
    }
}
